<?php
class Useradmin_Data_Editaction {
	
	private $database;
	private $secure;
	
	public function __construct(){
		$this->secure = new Core_Data_Secure;
		$this->database = new Core_Driver_MysqlImproved;
	}
	
	public function editUser(array $postVars){
		
		$postVars = $this->secure->parseData($postVars);
		
		$this->database->connect();
		
		$oldUserName = $postVars['oldUserNAme'];
		$username = $postVars['username'];
		$realname = $postVars['realname'];
		$email = $postVars['email'];
		$password = $postVars['password'];
		$banned = $postVars['banned'];
		$accessLevel = $postVars['accessLevel'];
		
		$oldUserName = $this->database->escape($oldUserName);
		$username = $this->database->escape($username);
		$realname = $this->database->escape($realname);
		$email = $this->database->escape($email);
		$password = $this->database->escape($password);
		$accessLevel = $this->database->escape($accessLevel);
		$banned = $this->database->escape($banned);
		
		$this->database->prepare(
			"
				update users set users_email = '$email', users_username = '$username', users_realname = '$realname', users_password = '$password', users_access_level = '$accessLevel', users_banned = '$banned' where users_username = '$oldUserName';
				"
		);
		$this->database->query();
		$this->database->dataOperations();
		echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?useradmin">';
	}
}